package charts.skins
{
	import mx.skins.ProgrammaticSkin;
	import mx.graphics.RectangularDropShadow;

	/**
	 * A skin shaped like a rectangle with a single color.
	 * 
	 * @langversion ActionScript 3.0
	 * @playerversion Flash 9
	 * @author Ivan Gong
	 */
	public class RectangleSkin extends ProgrammaticSkin implements IProgrammaticSkin
	{
		
	//--------------------------------------
	//  Constructor
	//--------------------------------------
	
		/**
		 * Constructor.
		 */
		public function RectangleSkin()
		{
			super();
		}
		
	//--------------------------------------
	//  Properties
	//--------------------------------------
		
		/**
		 * @private
		 * Storage for the fillColor property.
		 */
		private var _fillColor:uint = 0x0000FF;
		
		/**
		 * @copy com.yahoo.charts.skins.IProgrammaticSkin#fillColor
		 */
		public function get fillColor():uint
		{
			return this._fillColor;
		}
		
		/**
		 * @private
		 */
		public function set fillColor(value:uint):void
		{
			if(this._fillColor != value)
			{
				this._fillColor = value;
				this.invalidateDisplayList();
				this.invalidateProperties();
			}
		}
		
	//--------------------------------------
	//  Protected Methods
	//--------------------------------------
	
		/**
		 * @private
		 */
		/* override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			super.updateDisplayList(unscaledWidth,unscaledHeight);
			
			//since the Blaze component architecture rounds the position,
			//we need to account for that to make sure the mark displays correctly.
			var xDiff:Number = this.x - Math.round(this.x);
			var yDiff:Number = this.y - Math.round(this.y);
			
			this.graphics.clear();
			if(this.width == 0 || this.height == 0) return;
						
			this.graphics.lineStyle(2, 0x00FF00, 1);
			this.graphics.beginFill(this._fillColor, 1);
			this.graphics.drawRect(xDiff, yDiff, this.width, this.height);
			this.graphics.endFill();
			
			
			
		} */
		private var dropShadow:RectangularDropShadow;
		override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
		{
			var cornerRadius:Number = 5;//getStyle("cornerRadius");
			var backgroundColor:int = 0xff0000;//getStyle("backgroundColor");
			var backgroundAlpha:Number = 0.5;//getStyle("backgroundAlpha");
			graphics.clear();
			// Background
			drawRoundRect(0, 0, unscaledWidth, unscaledHeight, {tl: 0,tr:cornerRadius, bl: cornerRadius, br: 0}, backgroundColor, backgroundAlpha);
			// Shadow
			if (!dropShadow)
				dropShadow = new RectangularDropShadow();
			dropShadow.distance = 8;
			dropShadow.angle = 45;
			dropShadow.color = 0;
			dropShadow.alpha = 0.4;
			dropShadow.tlRadius = 0;
			dropShadow.trRadius = cornerRadius;
			dropShadow.blRadius = cornerRadius;
			dropShadow.brRadius = 0;
			dropShadow.drawShadow(graphics, 0, 0, unscaledWidth,unscaledHeight);
		}
	}
}